package com.zbkj.crmeb.member.controller;


import com.common.CommonPage;
import com.crmeb.core.common.CommonResult;
import com.common.PageParamRequest;
import com.zbkj.crmeb.member.model.MerchantMemberBenefits;
import com.zbkj.crmeb.member.service.IMerchantMemberBenefitsService;
import com.zbkj.crmeb.member.vo.MerchantMemberBenefitsVO;
import com.zbkj.crmeb.merchant.admin.controller.AdminBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 商户会员权益表 前端控制器
 * </p>
 *
 * @author xx
 * @since 2022-05-10
 */
@RestController
@RequestMapping("api/admin/mer/member/benefits")
@Api(tags = "商户会员权益")
public class MerchantMemberBenefitsController extends AdminBaseController {
    @Autowired
    private IMerchantMemberBenefitsService merchantMemberBenefitsService;

    @ApiOperation(value = "会员权益新增")
    @RequestMapping(value = "/addMemberBenefits", method = RequestMethod.POST)
    public CommonResult<String> addMemberBenefits(@RequestBody @Validated MerchantMemberBenefitsVO memberBenefitsVO, HttpServletRequest servletRequest){
        memberBenefitsVO.setMerId(getMerId(servletRequest));
        return merchantMemberBenefitsService.addMemberBenefits(memberBenefitsVO);
    }

    @ApiOperation(value = "会员权益查询")
    @RequestMapping(value = "/getMemberBenefits", method = RequestMethod.POST)
    public CommonResult<CommonPage<MerchantMemberBenefits>> getMemberBenefits(@Validated PageParamRequest pageParamRequest, HttpServletRequest servletRequest){
        return CommonResult.success(merchantMemberBenefitsService.getMemberBenefits(getMerId(servletRequest),pageParamRequest));
    }

    @ApiOperation(value = "会员权益编辑")
    @RequestMapping(value = "/updMemberBenefits", method = RequestMethod.POST)
    public CommonResult<Object> updMemberBenefits(@RequestBody @Validated MerchantMemberBenefitsVO memberBenefitsVO, HttpServletRequest servletRequest){
        memberBenefitsVO.setMerId(getMerId(servletRequest));
        return merchantMemberBenefitsService.updMemberBenefits(memberBenefitsVO) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "会员权益删除")
    @RequestMapping(value = "/delMemberBenefits", method = RequestMethod.GET)
    public CommonResult<Object> delMemberBenefits(@RequestParam Integer id, HttpServletRequest servletRequest){
        return merchantMemberBenefitsService.delMemberBenefits(id) ? CommonResult.success() : CommonResult.failed();
    }

}

